package vn.cuhanh.adapter;

import java.util.List;

import vn.cuhanh.R;
import vn.cuhanh.bean.Game;
import vn.cuhanh.utils.HelperFunc;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

public class GameListAdapter extends ArrayAdapter<Game> {

	public GameListAdapter(Context context,
			int textViewResourceId, List<Game> games) {
		super(context, textViewResourceId, games);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.choose_game_item, null);
		}
		final Game gameInfo = (Game)this.getItem(position);
		if(gameInfo != null) {
			ImageView gameImage = (ImageView) v.findViewById(R.id.game_item_image);
			//TODO add default image
//			UrlImageViewHelper.setUrlDrawable(gameImage, gameInfo.getImage());
			gameImage.setImageResource(this.getContext().getResources().getIdentifier(gameInfo.getNav_image(), "drawable", this.getContext().getPackageName()));
//			v.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					Log.d("itemInfo", gameInfo.getAppName());
//				}
//			});
		}
		return v;
	}

}
